/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model.Entity.SIS;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author user12
 */
@Entity
@Table(name = "SIS_TIMETABLE")
@NamedQueries({
    @NamedQuery(name = "Timetable.findAll", query = "SELECT s FROM Timetable s"),
    @NamedQuery(name = "Timetable.findBySemester", query = "SELECT s FROM Timetable s WHERE s.timetablePK.semester = :semester"),
    @NamedQuery(name = "Timetable.findByCampusNo", query = "SELECT s FROM Timetable s WHERE s.timetablePK.campusNo = :campusNo"),
    @NamedQuery(name = "Timetable.findByCourseNo", query = "SELECT s FROM Timetable s WHERE s.timetablePK.courseNo = :courseNo"),
    @NamedQuery(name = "Timetable.findByCourseEdition", query = "SELECT s FROM Timetable s WHERE s.timetablePK.courseEdition = :courseEdition"),
    @NamedQuery(name = "Timetable.findByActivityCode", query = "SELECT s FROM Timetable s WHERE s.timetablePK.activityCode = :activityCode"),
    @NamedQuery(name = "Timetable.findBySection", query = "SELECT s FROM Timetable s WHERE s.timetablePK.section = :section"),
    @NamedQuery(name = "Timetable.findByMinStudents", query = "SELECT s FROM Timetable s WHERE s.minStudents = :minStudents"),
    @NamedQuery(name = "Timetable.findByMaxStudents", query = "SELECT s FROM Timetable s WHERE s.maxStudents = :maxStudents"),
    @NamedQuery(name = "Timetable.findByGender", query = "SELECT s FROM Timetable s WHERE s.gender = :gender"),
    @NamedQuery(name = "Timetable.findByIsAllowed", query = "SELECT s FROM Timetable s WHERE s.isAllowed = :isAllowed"),
    @NamedQuery(name = "Timetable.findByEnrolledStudents", query = "SELECT s FROM Timetable s WHERE s.enrolledStudents = :enrolledStudents"),
    @NamedQuery(name = "Timetable.findByIsClosed", query = "SELECT s FROM Timetable s WHERE s.isClosed = :isClosed"),
    @NamedQuery(name = "Timetable.findByCheckType", query = "SELECT s FROM Timetable s WHERE s.checkType = :checkType"),
    @NamedQuery(name = "Timetable.findByEntryDate", query = "SELECT s FROM Timetable s WHERE s.entryDate = :entryDate"),
    @NamedQuery(name = "Timetable.findByTerminal", query = "SELECT s FROM Timetable s WHERE s.terminal = :terminal"),
    @NamedQuery(name = "Timetable.findByOsUser", query = "SELECT s FROM Timetable s WHERE s.osUser = :osUser"),
    @NamedQuery(name = "Timetable.findByPrintCount", query = "SELECT s FROM Timetable s WHERE s.printCount = :printCount"),
    @NamedQuery(name = "Timetable.findByPrintDate", query = "SELECT s FROM Timetable s WHERE s.printDate = :printDate"),
    @NamedQuery(name = "Timetable.findByPrintTerminal", query = "SELECT s FROM Timetable s WHERE s.printTerminal = :printTerminal"),
    @NamedQuery(name = "Timetable.findByPrintOsUser", query = "SELECT s FROM Timetable s WHERE s.printOsUser = :printOsUser"),
    @NamedQuery(name = "Timetable.findByFaculty", query = "Select s "
    													+ "FROM Timetable s, Course a, CourseActivity c " 
    													+ "WHERE s.timetablePK.courseNo = a.courseNo "
    													+ "AND s.timetablePK.courseNo = c.courseActivityPK.courseNo "
    													+ "AND s.timetablePK.courseEdition = c.courseActivityPK.courseEdition "
    													+ "AND s.timetablePK.activityCode = c.courseActivityPK.activityCode "
    													+ "AND a.faculty.facultyNo = :facultyNo "),
    @NamedQuery(name = "Timetable.findByFacultyAndDept", query = "Select s "
																+ "FROM Timetable s, Course a, CourseActivity c " 
																+ "WHERE s.timetablePK.courseNo = a.courseNo "
																+ "AND s.timetablePK.courseNo = c.courseActivityPK.courseNo "
																+ "AND s.timetablePK.courseEdition = c.courseActivityPK.courseEdition "
																+ "AND s.timetablePK.activityCode = c.courseActivityPK.activityCode "
																+ "AND a.faculty.facultyNo = :facultyNo "
																+ "AND a.dept.deptCode = :deptCode" )})
public class Timetable implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TimetablePK timetablePK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "MIN_STUDENTS")
    private short minStudents;
    @Basic(optional = false)
    @NotNull
    @Column(name = "MAX_STUDENTS")
    private short maxStudents;
    @Basic(optional = false)
    @NotNull
    private short gender;
    @Basic(optional = false)
    @NotNull
    @Column(name = "IS_ALLOWED")
    private short isAllowed;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ENROLLED_STUDENTS")
    private short enrolledStudents;
    @Basic(optional = false)
    @NotNull
    @Column(name = "IS_CLOSED")
    private short isClosed;
    @Basic(optional = false)
    @NotNull
    @Column(name = "CHECK_TYPE")
    private short checkType;
    @Basic(optional = false)
    @NotNull
    @Column(name = "ENTRY_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date entryDate;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    private String terminal;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "OS_USER")
    private String osUser;
    @Column(name = "PRINT_COUNT")
    private Short printCount;
    @Column(name = "PRINT_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date printDate;
    @Size(max = 30)
    @Column(name = "PRINT_TERMINAL")
    private String printTerminal;
    @Size(max = 30)
    @Column(name = "PRINT_OS_USER")
    private String printOsUser;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "timetable")
    private List<SectionTime> sectionTimeList;
    @JoinColumns({
        @JoinColumn(name = "COURSE_NO", referencedColumnName = "COURSE_NO", insertable = false, updatable = false),
        @JoinColumn(name = "COURSE_EDITION", referencedColumnName = "COURSE_EDITION", insertable = false, updatable = false),
        @JoinColumn(name = "ACTIVITY_CODE", referencedColumnName = "ACTIVITY_CODE", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private CourseActivity courseActivity;

    public Timetable() {
    }

    public Timetable(TimetablePK timetablePK) {
        this.timetablePK = timetablePK;
    }

    public Timetable(TimetablePK timetablePK, short minStudents, short maxStudents, short gender, short isAllowed, short enrolledStudents, short isClosed, short checkType, Date entryDate, String terminal, String osUser) {
        this.timetablePK = timetablePK;
        this.minStudents = minStudents;
        this.maxStudents = maxStudents;
        this.gender = gender;
        this.isAllowed = isAllowed;
        this.enrolledStudents = enrolledStudents;
        this.isClosed = isClosed;
        this.checkType = checkType;
        this.entryDate = entryDate;
        this.terminal = terminal;
        this.osUser = osUser;
    }

    public Timetable(int semester, short campusNo, short courseNo, short courseEdition, short activityCode, short section) {
        this.timetablePK = new TimetablePK(semester, campusNo, courseNo, courseEdition, activityCode, section);
    }

    public TimetablePK getTimetablePK() {
        return timetablePK;
    }

    public void setTimetablePK(TimetablePK timetablePK) {
        this.timetablePK = timetablePK;
    }

    public short getMinStudents() {
        return minStudents;
    }

    public void setMinStudents(short minStudents) {
        this.minStudents = minStudents;
    }

    public short getMaxStudents() {
        return maxStudents;
    }

    public void setMaxStudents(short maxStudents) {
        this.maxStudents = maxStudents;
    }

    public short getGender() {
        return gender;
    }

    public void setGender(short gender) {
        this.gender = gender;
    }

    public short getIsAllowed() {
        return isAllowed;
    }

    public void setIsAllowed(short isAllowed) {
        this.isAllowed = isAllowed;
    }

    public short getEnrolledStudents() {
        return enrolledStudents;
    }

    public void setEnrolledStudents(short enrolledStudents) {
        this.enrolledStudents = enrolledStudents;
    }

    public short getIsClosed() {
        return isClosed;
    }

    public void setIsClosed(short isClosed) {
        this.isClosed = isClosed;
    }

    public short getCheckType() {
        return checkType;
    }

    public void setCheckType(short checkType) {
        this.checkType = checkType;
    }

    public Date getEntryDate() {
        return entryDate;
    }

    public void setEntryDate(Date entryDate) {
        this.entryDate = entryDate;
    }

    public String getTerminal() {
        return terminal;
    }

    public void setTerminal(String terminal) {
        this.terminal = terminal;
    }

    public String getOsUser() {
        return osUser;
    }

    public void setOsUser(String osUser) {
        this.osUser = osUser;
    }

    public Short getPrintCount() {
        return printCount;
    }

    public void setPrintCount(Short printCount) {
        this.printCount = printCount;
    }

    public Date getPrintDate() {
        return printDate;
    }

    public void setPrintDate(Date printDate) {
        this.printDate = printDate;
    }

    public String getPrintTerminal() {
        return printTerminal;
    }

    public void setPrintTerminal(String printTerminal) {
        this.printTerminal = printTerminal;
    }

    public String getPrintOsUser() {
        return printOsUser;
    }

    public void setPrintOsUser(String printOsUser) {
        this.printOsUser = printOsUser;
    }

    public List<SectionTime> getSisSectionTimesList() {
        return sectionTimeList;
    }

    public void setSisSectionTimesList(List<SectionTime> sisSectionTimesList) {
        this.sectionTimeList = sisSectionTimesList;
    }

    public CourseActivity getSisCourseActivities() {
        return courseActivity;
    }

    public void setCourseActivity(CourseActivity courseActivity) {
        this.courseActivity = courseActivity;
    }

    public List<SectionTime> getSectionTimeList() {
		return sectionTimeList;
	}

	public void setSectionTimeList(List<SectionTime> sectionTimeList) {
		this.sectionTimeList = sectionTimeList;
	}

	public CourseActivity getCourseActivity() {
		return courseActivity;
	}

	@Override
    public int hashCode() {
        int hash = 0;
        hash += (timetablePK != null ? timetablePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Timetable)) {
            return false;
        }
        Timetable other = (Timetable) object;
        if ((this.timetablePK == null && other.timetablePK != null) || (this.timetablePK != null && !this.timetablePK.equals(other.timetablePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.Timetable[ TimetablePK=" + timetablePK + " ]";
    }
    
}
